package com.qlk.odcinterface.manager.impl;

import java.util.List;

import com.qlk.common.manager.BaseManager;
import com.qlk.common.utils.page.PageUtil;
import com.qlk.odcinterface.domain.PmsProductPromotionChannel;
import com.qlk.odcinterface.domain.query.PmsProductPromotionChannelQuery;
import com.qlk.odcinterface.dao.PmsProductPromotionChannelDao;
import com.qlk.odcinterface.manager.PmsProductPromotionChannelManager;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * PmsProductPromotionChannelManager接口的实现类
 * 
 * @author zhaoyanan
 * @version 2016-4-14 13:22:58
 * 
 */
@Component
public class PmsProductPromotionChannelManagerImpl extends BaseManager implements PmsProductPromotionChannelManager {
	
    @Autowired
    private PmsProductPromotionChannelDao pmsProductPromotionChannelDao;

    /**
     * {@inheritDoc}
     */
    public boolean insert(final List<PmsProductPromotionChannel> pmsProductPromotionChannelList) {
        boolean resultFlag = false;
        if (null != pmsProductPromotionChannelList && pmsProductPromotionChannelList.size() > 0) {
            for (PmsProductPromotionChannel pmsProductPromotionChannel : pmsProductPromotionChannelList) {
                resultFlag = pmsProductPromotionChannelDao.insert(pmsProductPromotionChannel);
                if (!resultFlag) {
                    throw new RuntimeException("批量新增表信息异常");
                }
            }
        }

        return resultFlag;
    }

    /**
     * {@inheritDoc}
     */
    public boolean insert(PmsProductPromotionChannel pmsProductPromotionChannel) {
        return pmsProductPromotionChannelDao.insert(pmsProductPromotionChannel);
    }

    /**
     * {@inheritDoc}
     */
    public boolean update(final PmsProductPromotionChannel pmsProductPromotionChannel) {
        return pmsProductPromotionChannelDao.update(pmsProductPromotionChannel);
    }

    /**
     * {@inheritDoc}
     */
    public List<PmsProductPromotionChannel> queryPmsProductPromotionChannelList(PmsProductPromotionChannelQuery queryBean) {
        return pmsProductPromotionChannelDao.queryPmsProductPromotionChannelList(queryBean);
    }

    /**
     * {@inheritDoc}
     */
    public List<PmsProductPromotionChannel> queryPmsProductPromotionChannelListWithPage(PmsProductPromotionChannelQuery queryBean,
            PageUtil pageUtil) {
        if (null == queryBean) {
            queryBean = new PmsProductPromotionChannelQuery();
        }

        // 查询总数
        int totalItem = queryPmsProductPromotionChannelCount(queryBean);

        if (pageUtil == null) {
            pageUtil = new PageUtil();
        }
        pageUtil.setTotalRow(totalItem);
        pageUtil.init();
        
        if (totalItem > 0) {
            queryBean.setPageIndex(pageUtil.getCurPage());
            queryBean.setPageSize(pageUtil.getPageSize());
            // 调用Dao翻页方法
            return pmsProductPromotionChannelDao.queryPmsProductPromotionChannelListWithPage(queryBean);
        }
        return null;
    }

    /**
     * {@inheritDoc}
     */
    public int queryPmsProductPromotionChannelCount(PmsProductPromotionChannelQuery queryBean) {
        return pmsProductPromotionChannelDao.queryPmsProductPromotionChannelCount(queryBean);
    }

    /**
     * {@inheritDoc}
     */
    public boolean delete(PmsProductPromotionChannel pmsProductPromotionChannel) {
        return pmsProductPromotionChannelDao.delete(pmsProductPromotionChannel);
    }
    
    public boolean deletePmsProductPromotionChannel(PmsProductPromotionChannel pmsProductPromotionChannel) {
        return pmsProductPromotionChannelDao.deletePmsProductPromotionChannel(pmsProductPromotionChannel);
    }
    /**
     * {@inheritDoc}
     */
    public PmsProductPromotionChannel getPmsProductPromotionChannelById(Integer id) {
        return pmsProductPromotionChannelDao.getPmsProductPromotionChannelById(id);
    }

    /**
     * {@inheritDoc}
     */
    public boolean delete(final PmsProductPromotionChannel[] pmsProductPromotionChannels) {
        boolean resultFlag = false;
        if (null != pmsProductPromotionChannels && pmsProductPromotionChannels.length > 0) {
            for (int i = 0; i < pmsProductPromotionChannels.length; i++) {
                resultFlag = delete(pmsProductPromotionChannels[i]);
                if (!resultFlag) {
                    throw new RuntimeException("批量删除表信息异常!");
                }
            }
        }

        return resultFlag;
    }

    /**
     * {@inheritDoc}
     */
    public boolean exist(PmsProductPromotionChannel pmsProductPromotionChannel) {
        return pmsProductPromotionChannelDao.exist(pmsProductPromotionChannel);
    }
}
